﻿<UserControl x:Class="VmroleAuthor.Views.ParametersView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"            
             mc:Ignorable="d" 
            d:DesignWidth="900">
    <UserControl.Resources>       
        <Style x:Key="TextBlockStyle" TargetType="{x:Type TextBlock}">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
                </Trigger>
            </Style.Triggers>            
        </Style>        
    </UserControl.Resources>
    <Grid VerticalAlignment="Top">
        <Grid.RowDefinitions >
            <RowDefinition Height="6" />
            <RowDefinition Height="Auto" />
            <RowDefinition MinHeight="30" />
            <RowDefinition Height="Auto" />
            <RowDefinition MinHeight="30" />
            <RowDefinition Height="Auto" />           
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>           
            <ColumnDefinition Width="6"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="6"/>
        </Grid.ColumnDefinitions>

        <TextBlock  Grid.Row="1" Grid.Column="1" >Parameters should be updated automatically based on the usage. Edit this only if manual over-ride is required. </TextBlock>
        
        <DataGrid  x:Name="Parameters" Grid.Row="3" Grid.Column="1" AutoGenerateColumns="False" IsReadOnly="False" CanUserAddRows="False" CanUserDeleteRows="False" ItemsSource="{Binding Parameters, ValidatesOnExceptions=True}">
            <DataGrid.RowStyle>
                <Style TargetType="DataGridRow">
                    <Setter Property="ValidationErrorTemplate" Value="{x:Null}"/>
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="BorderBrush" Value="Blue" />
                            <Setter Property="BorderThickness" Value="2" />
                            <Setter Property="Background" Value="LightBlue" />
                            <Setter Property="Foreground" Value="Black" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.RowStyle>
            <DataGrid.CellStyle>
                <Style TargetType="DataGridCell">
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Background" Value="White" />
                            <Setter Property="Foreground" Value="Black" />                            
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.CellStyle>         
            <DataGrid.Columns>
                <DataGridTemplateColumn Header="Name" MinWidth="350">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Style="{StaticResource ResourceKey=TextBlockStyle}" Text="{Binding Name, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Name, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, Mode=TwoWay,  NotifyOnValidationError=True}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Type"  MinWidth="100">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Style="{StaticResource ResourceKey=TextBlockStyle}" Text="{Binding Type, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <ComboBox x:Name="Type"
                                      ItemsSource="{Binding  AvailableTypes}" 
                                      SelectedItem="{Binding SelectedType, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"                                       
                                      />                           
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Description" MinWidth="400">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Style="{StaticResource ResourceKey=TextBlockStyle}" Text="{Binding Description, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Description, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, Mode=TwoWay,  NotifyOnValidationError=True}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>

        <!-- Insert or Delete Rows using button -->
        <StackPanel Orientation = "Horizontal" HorizontalAlignment="Left" Grid.Row="5" Grid.Column="1" >
            <Grid>
                <Grid.RowDefinitions >
                    <RowDefinition Height="6" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="6" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>                    
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="10"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Button Grid.Row="1" Grid.Column="0" Command="{Binding AddParameterCommand}" >
                    <StackPanel Orientation = "Horizontal" HorizontalAlignment="Right">
                        <TextBlock HorizontalAlignment="Center">Insert</TextBlock>
                        <Image Source="..\Img\addgreen.png" Width="20" Height="20"></Image>
                    </StackPanel>
                </Button>
                <Button Grid.Row="1" Grid.Column="2" Command="{Binding RemoveParameterCommand}" CommandParameter="{Binding ElementName=Parameters, Path=SelectedItem}">
                    <StackPanel Orientation = "Horizontal" HorizontalAlignment="Right">
                        <TextBlock HorizontalAlignment="Center">Delete</TextBlock>
                        <Image Source="..\Img\deletered.png" Width="20" Height="20"></Image>
                    </StackPanel>
                </Button>
            </Grid>
        </StackPanel>
    </Grid>
</UserControl>
